package com.leetcode.arr;

/**
 * @program: leetcode
 * @author: jzhou
 * @date: 2022-11-22 21:41
 * @version: 1.0
 * @description: 买卖股票的最佳时机
 **/
public class MaxProfit {
    public int maxProfit(int[] prices) {
        int minElement = prices[0];
        int profit = 0;
        for (int price : prices) {
            if (price < minElement ){
                minElement = price;
            }else{
                profit = price - minElement;
            }
        }
        return profit;
    }
}
